package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.packers.PackersFinanceEntity;
import com.sgb.kjwl.model.entity.self.SelfTeamChildEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
*@author 毁灭霸者
*@date 2020/7/1
*description:
*/
public class PackersFinanceAdapter extends BaseRecycleAdapter<PackersFinanceEntity> {
    private boolean showDel = false;
    private ItemCallBack itemCallBack;

    public PackersFinanceAdapter(Context context, List<PackersFinanceEntity> data) {
        super(context, R.layout.item_packers_finance, data);
    }

    @Override
    public void convert(ItemViewHolder holder, final PackersFinanceEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        LinearLayout delLayout = holder.getItem().findViewById(R.id.del_layout);
        TextView delView = holder.getItem().findViewById(R.id.del_view);
        TextView typeView = holder.getItem().findViewById(R.id.tv_team_type);
        LinearLayout companyLayout = holder.getItem().findViewById(R.id.company_layout);
        LinearLayout areaLayout = holder.getItem().findViewById(R.id.area_layout);
        if (showDel) {
            companyLayout.setVisibility(View.GONE);
            delLayout.setVisibility(View.VISIBLE);
            areaLayout.setVisibility(View.VISIBLE);
        } else {
            delLayout.setVisibility(View.GONE);
            companyLayout.setVisibility(View.VISIBLE);
            areaLayout.setVisibility(View.GONE);
        }
        delView.setOnClickListener(v -> {
            if (itemCallBack != null) {
                itemCallBack.del(entity.getId());
            }
        });
        List<SelfTeamChildEntity> list = entity.getTeamChildEntityList();
        if (list != null) {
            StringBuilder sb = new StringBuilder();
            for (SelfTeamChildEntity entity1 : list) {
                sb.append(entity1.getFirstCategoryName()).append("、");
            }
            String type = sb.substring(0, sb.length() - 1);
            typeView.setText(type);
        }
    }

    public void setShowDel(boolean showDel) {
        this.showDel = showDel;
    }

    public void setItemCallBack(ItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;
    }

    public interface ItemCallBack {
        void del(String id);
    }
}
